package ws.wsAOP.framework.aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class LogInvacationHandle implements InvocationHandler{
	private Object proxy;
	private Object target;
	
	public Object bind(Object target,Object proxy){
		this.target = target;
		this.proxy = proxy;
		return Proxy.newProxyInstance(this.getClass().getClassLoader(), this.target.getClass().getInterfaces(), this);
	}

	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		Class clazz = this.proxy.getClass();
		Method start = clazz.getDeclaredMethod("start", null);
		start.invoke(this.proxy, null);
		method.invoke(this.target, args);
		
		Method end = clazz.getDeclaredMethod("end", new Class[]{Method.class});
		end.invoke(this.proxy, new Object[]{method});
		return null;
	}

}
